package cn.dmp.tags

import org.apache.commons.lang.StringUtils
import org.apache.spark.broadcast.Broadcast
import org.apache.spark.sql.Row

/**
  * APP标签
  * Created by Administrator on 2018/4/29.
  */
object Tags4App extends Tags{

  override def makeTags(args: Any*): Map[String, Int] = {

    //转换第一个参数的类型
    val row = args(0).asInstanceOf[Row]
    val appDicBD = args(1).asInstanceOf[Broadcast[Map[String,Int]]]
    var tags = Map[String,Int]()
    //APP类型
    val appid = row.getAs[String]("appid")
    var appName = row.getAs[String]("appname")

    val appvalue = appDicBD.value
    if (StringUtils.isEmpty(appName)) {
      if (StringUtils.isNotEmpty(appid)) {
        val appName = appvalue.getOrElse(appid, appid)
        tags += "APP" + appName -> 1
      }
    } else tags += "APP" + appName -> 1

    tags
  }
}
